package com.qf.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 *
 * @Configuration: 表示该类为配置类
 * @Bean:标记在方法上，会将方法的返回值存储到ioc容器中
 * @author 千锋教育
 * @Company http://www.mobiletrain.org/
 * @Version 1.0
 */
@Configuration
public class RabbitMqConfig {

    //创建绑定对象
    //绑定 广播模式
    @Bean
    public Binding binding1(FanoutExchange exchange, Queue createQueue01){
        return BindingBuilder.bind(createQueue01).to(exchange);
    }

    @Bean
    public Binding binding2(FanoutExchange exchange, Queue createQueue02 ){
        return BindingBuilder.bind(createQueue02).to(exchange);
    }


    //绑定路由模式交换机
    @Bean
    public Binding binding3(DirectExchange exchange, Queue createQueue01){
        return BindingBuilder.bind(createQueue01).to(exchange).with("update");
    }

    @Bean
    public Binding binding4(DirectExchange exchange, Queue createQueue02 ){
        return BindingBuilder.bind(createQueue02).to(exchange).with("log");
    }

    //创建交换机
    /**
     * 交换机的类型
     *      广播: FanoutExchange
     *      路由: DirectExchange
     *      主体: TopicExchange
     * @return
     */
    @Bean
    public TopicExchange createExchange1(){
        return new TopicExchange("my-topic-exchange", false, false);
    }

    @Bean
    public DirectExchange createExchange2(){
        return new DirectExchange("my-direct-exchange", false, false);
    }

    @Bean
    public FanoutExchange createExchange3(){
        return new FanoutExchange("my-fanout-exchange", false, false);
    }


    //创建队列
    @Bean
    public Queue createQueue02(){
        return new Queue("my-queue2", true, false, false);
    }

    //创建队列
    @Bean
    public Queue createQueue01(){
        return new Queue("my-queue1", true, false, false);
    }
}
